package com.hnas.sys.web.basic;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hnas.sys.service.upload.UploadService;
import com.hnas.sys.service.upload.dto.DTOAttachment;

@Controller
@RequestMapping("/noframe/attachment")
public class AttachmentControl {
	private static Log log = LogFactory.getLog(AttachmentControl.class);
	@Autowired
	private UploadService uploadService;
	@RequestMapping("/showFile")
	//前台发送短信验证码
	public String sendAuthCode(long id, int authCode,HttpServletResponse response) {

		try {
			DTOAttachment at = this.uploadService.getAttchment(id, authCode);
			response.setContentType( at.getContentType() );
			response.setHeader( "Content-Disposition", "inline; filename=" + at.getUserFileName() );
			this.uploadService.downLoadFile(at.getFileName(), response.getOutputStream());
			return null;
		} catch (Exception e) {
			log.error("",e);
		}
		return null;
	}
}
